<template>
  <div style="position:relative ; margin-top: 50px;">
    <div class="myButton">

      <div v-for="(item, index) in tab1List" :key="index" @click="selTab1Option(item)">
        <span class="tab1-btn" :class="{ tab1Selected: item.isActive }">{{
          item.text
        }}</span>
      </div>
    </div>

    <transition name="fade">
      <cityindex v-if="componentType == 1"></cityindex>
      <shengdiao v-else></shengdiao>
    </transition>
    <!-- <component :is="myComponent" @business-city-reload="reload"></component> -->
  </div>
</template>

<script>
import * as echarts from "echarts";
import cityindex from './cityindex';
import shengdiao from './shengdiao';
export default {
  name: "business-city",
  components: {
    cityindex,
    shengdiao
  },
  data() {
    return {
      tab1List: [
        { text: "地区风险分析", id: 0, isActive: true },
        { text: "省调需求响应", id: 1, isActive: false },
      ],
      componentType: 1,
      myComponent: 'cityindex'
    }
  },
  created() {

    let myPageType = this.getPageTypeFromOpenedWindow() || 1
    // let myPageType = 3
    if(myPageType == 3){
      this.componentType = 2

      this.tab1List = [
        { text: "地区风险分析", id: 0, isActive: false },
        { text: "省调需求响应", id: 1, isActive: true },
      ]
    }


  },
  mounted() {

  },
  methods: {
    getPageTypeFromOpenedWindow() {
      // 使用 URLSearchParams 获取参数
      const urlParams = new URLSearchParams(window.location.search);
      const PAGETYPE = urlParams.get("PAGETYPE");

      // 如果找到 PAGETYPE 参数，则转换为数字类型并返回
      if (PAGETYPE !== null) {
        return parseInt(PAGETYPE, 10);
      }

      // 如果未找到 PAGETYPE 参数，返回 null
      return null;
    },


    selTab1Option(data) {
      if (!data.isActive) {
        this.tab1List.forEach(function (obj) {
          obj.isActive = false;
        });
        data.isActive = true;
      }

      if (data.text === '地区风险分析') {
        this.componentType = 1

      } else {
        this.componentType = 2

      }
    },

    changeComponet(v) {


    },


    reload(comp) {
      this.myComponent = comp;
    }
  },
};
</script>

<style scoped lang="scss">
.myButton {
  position: absolute;
  top: -60px;
  left: 740px;
  z-index: 9999;

  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px 15px;
}

.tab1-btn {
  display: block;
  width: 180px;
  height: 42px;
  line-height: 42px;
  text-align: center;
  /* border-radius: 12px; */
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  color: #00706b;
  background: url(../../../assets/images/tab-unsel.png) center no-repeat;
  background-size: 100% 100%;
}

.tab1Selected {
  background: url(../../../assets/images/tab-sel.png) center no-repeat;
  background-size: 100% 100%;
  color: #2d3b4d;
}
</style>
